import { createRouter, createWebHistory } from 'vue-router'

import { createRouterGuard } from './guard'

import { routes } from './routes'

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: routes,
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition
        } else {
            return { left: 0, top: 0 }
        }
    },
})

// 创建路由导航守卫
createRouterGuard(router)

export default router
